var we = new Vue({
	el: "#app",
	data: {
		fv: false,
		arr: [],
		et: "df",
		bb: "",
		ws: "",
		wert: 0,
		er: "",
		but: false,
		we: ""
		/*[{
						url: "./img/5adef3e6N3b3d085a.jpg",
						message: "开间茶馆吧。在某个临水的地方，不招摇，不繁闹。有一些古旧，一些单薄,生意冷清，甚至被人",
						price: 32.90,
						num: 0,
						checked: false
					},
					{
						url: "./img/5b6299fdNa2588a6a.jpg",
						message: "开间茶馆吧。在某个临水的地方，不招摇，不繁闹。有一些古旧，一些单薄,生意冷清，甚至被人",
						price: 109.00,
						num: 0,
						checked: false
					},
					{
						url: "./img/5b779a23N8e4604a5.jpg",
						message: "开间茶馆吧。在某个临水的地方，不招摇，不繁闹。有一些古旧，一些单薄,生意冷清，甚至被人",
						price: 59.90,
						num: 0,
						checked: false
					},
					{
						url: "./img/5b7cb4b6Nce1debe2.jpg",
						message: "开间茶馆吧。在某个临水的地方，不招摇，不繁闹。有一些古旧，一些单薄,生意冷清，甚至被人",
						price: 37.90,
						num: 0,
						checked: false
					},
					{
						url: "./img/5bc040b3N96bdc3cd.jpg",
						message: "开间茶馆吧。在某个临水的地方，不招摇，不繁闹。有一些古旧，一些单薄,生意冷清，甚至被人",
						price: 19.90,
						num: 0,
						checked: false
					}
				] */
	},
	methods: {
		ed: function() {
			this.we = "";
			this.but = true;
			this.fv = false;
			document.getElementById("sure").disabled = "disabled";

		},
		add: function(e) {
			this.we[e].num++;


		},
		subtract: function(e) {
			if (this.we[e].num <= 0) {
				alert('不能再少了,铁子')
				this.count = 0;
			} else {
				this.we[e].num -= 1;
			}
		},
		wq: function(e) {

			var arrs = [];
			this.we[e].checked = !this.we[e].checked

			for (var i = 0; i < this.we.length; i++) {

				arrs.push(this.we[i].checked);

			}
			if (arrs.indexOf(false) == -1) {
				this.fv = true

			} else {
				this.fv = false
			}

		},

		fun(e) {
			var arrs = [];
			this.ws = e;
			if (this.ws !== (this.we.length - 1)) {
				this.we[this.ws].checked == this.we[this.ws + 1].checked;

			} else {

			}
			this.we.splice(e, 1)
			for (var i = 0; i < this.we.length; i++) {

				arrs.push(this.we[i].checked);

			}
			if (arrs.indexOf(false) == -1) {
				this.fv = true
			} else {
				this.fv = false
			}

		},
		// },
		sd: function() {
			console.log(this.we.length)
			this.we.forEach(item=>{
				item.checked = !this.fv
			})
		},
		wer: function(index) {

			return Math.floor(this.we[index].price * Number(this.we[index].num));

		},

		sde: function() {
			var total = 0;
			for (var i = 0; i < this.we.length; i++) {
				if (this.we[i].checked) {
					total += parseInt(this.we[i].num);
				}
			}
			return total;
		},
		wry: function() {
			var totall = 0;
			for (var i = 0; i < this.we.length; i++) {
				if (this.we[i].checked) {
					totall += parseInt(this.we[i].num * this.we[i].price);
				}
			}
			return totall;
		},
		getdata(){
			$.ajax({
				type: "get",
				url: "http://jx.xuzhixiang.top/ap/api/cart-list.php",
				data: {
					id: localStorage.getItem("uid")
				},
				success: (res) => {
					console.log(res.data)
					let arr = res.data.map(item => {
						return {
							url: item.pimg,
							message: item.pname,
							price: item.pprice,
							num: item.pnum,
							checked: false,
							pid:item.pid
						}
					})
					this.we = arr
				}
			})
		},
		// shanchu 删除
		shanchu(item){
			// console.log(item)
			$.ajax({
				type:"get",
				url:"http://jx.xuzhixiang.top/ap/api/cart-delete.php",
				data:{
					uid:localStorage.getItem("uid"),
					pid:item.pid
				},
				success:(res)=>{
					alert(res.msg)
					this.getdata()
				}
			})
		}
		
	},
	computed: {
		length() {
			return this.we.length;
		}

	},
	created() {
		// if (!this.we) {
		// 	// this.ert=true;
		// 	this.but = true;
		// 	this.fv = false;
		// 	document.getElementById("sure").disabled = "disabled";
		// }
		this.getdata()
	}
})
